package cn.orange.ch07_binarytree;

import cn.orange.TreeNode;

/**
 * LC101.对称二叉树
 */
public class LC101 {
    public boolean isSymmetric(TreeNode root) {
        return compareTree(root.left, root.right);
    }

    private boolean compareTree(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null) {
            return false;
        }
        if (right == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        return compareTree(left.left, right.right) && compareTree(left.right, right.left);
    }

}
